﻿using System;
using MachineVision.Common;
using MachineVision.Core;
using MachineVision.Models;
using MachineVision.Services;
using MachineVision.Views;
using MaterialDesignColors;
using Prism.Commands;
using Prism.Regions;

namespace MachineVision.ViewModels
{
    public class MainViewModel : NavigationViewModel
    {
        public MainViewModel(INavigationService navigation, IRegionManager regionManager)
        {
            Navigation = navigation;
            RegionManager = regionManager;
        }

        private DelegateCommand<NavigationItem> _cmdOnMenuClick;
        public DelegateCommand<NavigationItem> CmdOnMenuClick =>
            _cmdOnMenuClick
            ?? (_cmdOnMenuClick = new DelegateCommand<NavigationItem>(ExecuteCmdOnMenuClick));

        void ExecuteCmdOnMenuClick(NavigationItem parameter)
        {
            if (parameter != null)
                if (parameter.Key.Contains("All"))
                    IsTopDrawerOpen = true;
                else
                    IsTopDrawerOpen = false;
            RegionManager.RequestNavigate(Regions.MainViewRegion, parameter.PageName);
        }

        private bool _isTopDrawerOpen;
        public bool IsTopDrawerOpen
        {
            get { return _isTopDrawerOpen; }
            set { SetProperty(ref _isTopDrawerOpen, value); }
        }

        public INavigationService Navigation { get; }
        public IRegionManager RegionManager { get; }

        public override void OnNavigatedTo(NavigationContext navigationContext)
        {
            Navigation.InitMenus();
            RegionManager.RequestNavigate(Regions.MainViewRegion, nameof(DashboardView));
            base.OnNavigatedTo(navigationContext);
        }
    }
}
